﻿namespace Middleware
{
    /// <summary>
    /// 使用约定激活的中间件
    /// </summary>
    public class ConventionalMiddleware
    {
        private readonly RequestDelegate _next;

        public ConventionalMiddleware(RequestDelegate next)
            => _next = next;

        public async Task InvokeAsync(HttpContext context)
        {
            var keyValue = context.Request.Query["key"];

            if (!string.IsNullOrWhiteSpace(keyValue))
            {
                await context.Response.WriteAsync($"Output: key—{keyValue}");
            }

            await _next(context);
        }
    }
}
